package cn.iocoder.yudao.module.iot.gateway.protocol.tcp.detector;

import io.vertx.core.net.NetSocket;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class PortMappingDetectionStrategy  implements ProtocolDetectionStrategy {

    private final Map<Integer, String> portProtocolMap = new HashMap<>();
    private final Set<String> supportedProtocols;

    public PortMappingDetectionStrategy() {
        // 初始化支持的协议类型
        supportedProtocols = Collections.singleton("port-mapping");
    }

    public void registerPortProtocol(int port, String protocol) {
        portProtocolMap.put(port, protocol);
    }

    @Override
    public String detectProtocol(byte[] data, NetSocket socket) {
        int localPort = socket.localAddress().port();
        return portProtocolMap.get(localPort);
    }

    @Override
    public int getPriority() {
        return 5; // 更高优先级
    }

    @Override
    public Set<String> getSupportedProtocols() {
        return supportedProtocols;
    }
}
